﻿using System;
using System.Collections.Generic;
using System.Windows;
using System.Linq;
using ChessKit.Ui.ChessPanel;
using Microsoft.Expression.Media;

namespace ChessKit.Ui.Arrows
{
  public partial class BoardArrow : IBoardedElement
  {
    public BoardArrow()
    {
      InitializeComponent();
    }

    public void SetCells(IEnumerable<Rect> cell)
    {
      var f = cell.First();
      var s = cell.Last();
           
           if (f.X < s.X && f.Y < s.Y) _line.StartCorner = CornerType.TopLeft;
      else if (f.X < s.X && f.Y > s.Y) _line.StartCorner = CornerType.BottomLeft;
      else if (f.X > s.X && f.Y < s.Y) _line.StartCorner = CornerType.TopRight;
      else if (f.X > s.X && f.Y > s.Y) _line.StartCorner = CornerType.BottomRight;

      var k = Math.Sqrt(f.Width);
      _line.ArrowSize = k * 1.6;
      _line.Margin = new Thickness(f.Width / 2 - k);
      _line.StrokeThickness = k;
    }
  }
}
